/*
    Javascript functions for the main calendar
*/

function changeTab(obj) {
    if (!obj.hasClass('selected')) {
        $$('td.side-bar-tab').removeClass('selected');
        obj.addClass('selected');

        $$('div.side-bar-page').removeClass('selected');
        var divID = obj.id.replace(/tab/, 'container');
        $(divID).addClass('selected');
    }
}

function eventSearch() {
    if ($('search-input').value) {
        var req = new Request({
            method: 'post',
            url: 'main/event_search',
            data: { 'search' : $('search-input').value },
            async: true,
            onComplete: function(response) {
                var data = JSON.decode(response);
                $('results-container').set('html', data);
            }
        }).send();
    }
}

window.addEvent('domready', function() {
    if ($('tab-table')) {
        $$('td.side-bar-tab').addEvent('click', function(e){
            changeTab(this);
        });

        $('search-button').addEvent('click', function(e){
            eventSearch();
        });
    }
});


